﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace NerdDinnerReloaded.Models
{
    public class Dinner : NerdDinnerEntity
    {
        [Required(ErrorMessage = "Please enter a Dinner Title")]
        [StringLength(20, ErrorMessage = "Title is too long")]
        public string Title { get; set; }

        [Required(ErrorMessage = "Please enter the Date of the Dinner")]
        public DateTime EventDate { get; set; }

        [Required(ErrorMessage = "Please enter the location of the Dinner")]
        [StringLength(30, ErrorMessage = "Address is too long")]
        public string Address { get; set; }

        [Required(ErrorMessage = "Please enter your email address")]
        [RegularExpression(".+\\@.+\\..+", ErrorMessage = "Please enter a valid email address")]
        public string HostedBy { get; set; }

        public virtual ICollection<RSVP> RSVPs { get; set; }
    }

    public class DinnerConfiguration : EntityConfiguration<Dinner>
    {
        public DinnerConfiguration()
            : base()
        {
            MapSingleType(d => new
                                   {
                                       dinner_id = d.ID,
                                       title = d.Title,
                                       event_date = d.EventDate,
                                       address = d.Address,
                                       hosted_by = d.HostedBy,
                                       created_dttm = d.CreatedOn,
                                       created_by = d.CreatedBy,
                                       modified_by = d.ModifiedBy,
                                       modified_on = d.ModifiedOn
                                   }).ToTable(new StoreTableName("tbDinner", "dbo")); // or just use .ToTable("dbo.tbDinner") 
        }
    }
}